function dec = oct2dec(oct)
  t = typeof(oct);
  select t
    case 'constant' then
      dec = oct2dec_const(oct);
    case  'polynomial' then
      dec = oct2dec_poly(oct);
    case  'string' then
      dec = oct2dec_str(oct);
    else
      error('input data type must be either constant, polynomial or string');
  end
endfunction  

function dec = oct2dec_poly(oct)
  dec = zeros(oct);
  for i = 1:length(oct)
    coef = coeff(oct(i));
    decNum = 0;
    weight = 1;
    for j = 1:length(coef)
      decNum = decNum + coef(j)*weight;
      weight = weight * 8;
    end
    dec(i) = decNum;
  end
  
endfunction

function dec = oct2dec_str(oct)
  dec = oct2dec(eval(oct))
endfunction

function dec = oct2dec_const(oct)
    if int(oct) ~= oct | min(oct) < 0
        error('input number must be positivve integer');
    end
    dec = zeros(oct);
    for i = 1:length(oct)
      octNum = oct(i);
      decNum = 0;
      weight = 0;
      while octNum > 0
        decNum = decNum + modulo(octNum, 10)*(8^weight);
        octNum = int(octNum/10);
        weight = weight + 1;
      end
      dec(i) = decNum;
    end
  
endfunction

